#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.bean.vo;

import ${package}.common.bean.po.DataTree;
import ${package}.common.emum.CommonStatusEnum;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serializable;
import java.util.List;

/**
 * Description: Code po
 *
 * @author wenxiaopeng
 * @date 2020/07/24 14:00
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "代码VO")
public class CodeVo implements DataTree<CodeVo>, Serializable {

	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "代码ID")
	private Long id;

	@ApiModelProperty(value = "代码值")
	private String code;

	@ApiModelProperty(value = "业务代码")
	private String aka;

	@ApiModelProperty(value = "代码含义")
	private String value;

	@ApiModelProperty(value = "上级代码ID")
	private Long upperCodeId;

	@ApiModelProperty(value = "代码类型ID")
	private Long codeTypeId;

	@ApiModelProperty(value = "代码顺序")
	private Integer codeOrder;
	/**
	 * 代码状态
	 * @see ${package}.common.emum.CommonStatusEnum
	 **/
	@ApiModelProperty(value = "代码状态 1-启用 0-禁用")
	private Integer status;

	@ApiModelProperty(value = "子级代码列表")
	private List<CodeVo> codes;

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}

		if (o == null || getClass() != o.getClass()) {
			return false;
		}

		CodeVo code1 = (CodeVo) o;

		return new EqualsBuilder()
				.append(id, code1.id)
				.append(code, code1.code)
				.append(value, code1.value)
				.append(upperCodeId, code1.upperCodeId)
				.append(codeTypeId, code1.codeTypeId)
				.append(status, code1.status)
				.isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37)
				.append(id)
				.append(code)
				.append(value)
				.append(upperCodeId)
				.append(codeTypeId)
				.append(status)
				.toHashCode();
	}

	/**
	 * Description:
	 * <获得父级id>
	 *
	 * @return java.lang.Long
	 * @author YL
	 * @date 16:06 2019/8/8
	 **/
	@Override
	@JSONField(serialize = false)
	public Long getParentId() {
		return upperCodeId;
	}

	/**
	 * Description:
	 * <获得子列表>
	 *
	 * @param childList 1
	 * @author YL
	 * @date 16:08 2019/8/8
	 **/
	@Override
	public void setChildList(List<CodeVo> childList) {
		this.codes = childList;
	}

	@Override
	@JSONField(serialize = false)
	public List<CodeVo> getChildList() {
		return this.codes;
	}

	/** 转ApiVo，美化部分字段 */
	public CodeApiVo asApiVo() {
		return CodeApiVo.builder()
				.id(id)
				.code(code)
				.value(value)
				.order(codeOrder)
				.upperCodeId(upperCodeId)
				.enable(CommonStatusEnum.STATUS_VALID.getCode().equals(status))
				.aka(aka).build();
	}
}
